<?php
class login extends Controller {

	public $viewData;
	
	function login() {
		parent::Controller();
		$this->load->helper('url');
		$this->load->library('cartpool');
		$this->load->model('user');
	}
	
	function signin() {
		//$groupname = strtolower($_REQUEST['groupname']);
		$email = strtolower($_REQUEST['email']);
		$password = md5($_REQUEST['password']);
		
		$this->viewData->loginError = $this->cartpool->login($email, $password);
		$this->viewData->cartpoolData = $this->cartpool->getCartpoolData();
		
		$this->load->view('register_login', $this->viewData);
	}
	
	function register(){
		$groupname = $_REQUEST['reg_groupname'];
		$name = $_REQUEST['reg_name'];
		$email = strtolower($_REQUEST['reg_email']);
		$password = md5($_REQUEST['reg_password']);
				
		$userExists = $this->cartpool->get_user_by_email($email);
		
		if($userExists){
			$this->viewData->registerError = "This user already exists";
		}else{
			$this->cartpool->register_user($email, $name, $groupname, $password);	
			$this->viewData->registerError = "Registered succesfully, <a class='loginSucces' href='#login'>click to login</a>";
		}
		$this->load->view('register_login', $this->viewData);
	}
}